var subsetsWithDup = function (nums) {
  nums.sort((a, b) => {
    return a - b
  })
  let res = [], path = []
  const helper = (startIndex) => {
    res.push(path.slice(0))
    if (startIndex > nums.length - 1) {
      return
    }
    for (let i = startIndex; i < nums.length; i++) {
      if (i > startIndex && nums[i] === nums[i - 1]) {
        continue
      }
      path.push(nums[i])
      helper(i + 1)
      path.pop()
    }
  }
  helper(0)
  console.log(res);
  return res
};

subsetsWithDup([4, 4, 4, 1, 4])